{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "id": "e684b932",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "id": "e239d31b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Read DPCD Data: 14 14 C4 41 00 10 01 C0 02 00 00 00 1F 0B 80 00\n"
     ]
    },
    {
     "data": {
      "text/plain": [
       "{'DPCD v.': '1.4', 'Max Link Rate': '5.4Gbps/lane', 'Max Lane Count': '4-lane'}"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        read_data = card_lib.read_dpcd(0x0000, 16)\n",
    "        print(\"Read DPCD Data:\", read_data.hex(\" \").upper())\n",
    "\n",
    "        display(card_lib.parse_dpcd(read_data))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "1bc55b4e",
   "metadata": {},
   "source": [
    "# 修改vcom"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "id": "8c53a866",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.write_vcom(0x01)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "134d0078",
   "metadata": {},
   "source": [
    "# 修改PMIC AVDD AVEE\n",
    "### 用于NVP PMIC"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "id": "a7a4e173",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x46,0x03,[0x1F*2])\n",
    "        card_lib.iic_over_aux_write(0x46,0x04,[0x1F])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8a1121aa",
   "metadata": {},
   "source": [
    "### 用于NT50805"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "52dcb0f6",
   "metadata": {},
   "outputs": [],
   "source": [
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x46,0x01,[0x87])\n",
    "\n",
    "        card_lib.iic_over_aux_write(0x46,0x05,[0x05])\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "e6118fb7",
   "metadata": {},
   "source": [
    "# 修改Gama L0\n",
    "\n",
    "Gmama寄存器仅用于ANX2176  不兼容2177"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "id": "d7d2dffd",
   "metadata": {},
   "outputs": [],
   "source": [
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        card_lib.change_gamma(0x74,0xFF)\n",
    "        card_lib.change_gamma(0x73,0x00)\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "8f3e54a6",
   "metadata": {},
   "source": [
    "# 获取全体Gamma"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "83581f0b",
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "reg:  ['69', '6a', '6b', '6c', '6d', '6e', '6f', '70', '71', '72', '73', '74', '75', '76', '77', '78', '79', '7a', '7b', '7c', '7d', '7e']\n",
      "val:  ['00', '0b', '4a', '6d', 'b0', 'ba', '7f', 'b2', 'c8', 'e4', 'ee', '11', '1b', '37', '4d', '80', '45', '4f', '92', 'b5', 'f4', 'ff']\n"
     ]
    }
   ],
   "source": [
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # TCON Can be accessed after writing password\n",
    "        card_lib.write_dpcd(0x004F5, b\"\\x41\\x56\\x4F\\x20\\x16\")\n",
    "        card_lib.write_dpcd(0x004F0, b\"\\x0E\\x00\\x00\\x00\")\n",
    "\n",
    "        card_lib.write_dpcd(0x004F3, b\"\\x01\")\n",
    "\n",
    "        # 0X69-0X7E对应P255 ... P0 N0 ...N0，共22个帮点,同一灰阶正负极性绑点间之和=255时，gamma对称\n",
    "        gamma_list = []\n",
    "        for i in range(0x69, 0x7E+1,1):\n",
    "            card_lib.write_dpcd(0x004F0, b\"\\x0A\\x00\\x00\"+ bytes([i]))\n",
    "            gamma_list.append(card_lib.read_dpcd(0x004F4, 1))\n",
    "\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "\n",
    "        print(\"gray: \",[\"L255+\",\"L254+\",\"L247+\",\"l224+\",\"L192+\",\"L128+\",\"L64+\",\"L32+\",\"L7+\",\"L1+\",\"L0+\",\"L0-\",\"L1-\",\"...\"])\n",
    "        print(\"reg: \",[hex(i)[2:] for i in range(0x69, 0x7E+1,1)])\n",
    "        print(\"val: \",[i.hex() for i in gamma_list])\n",
    "\n",
    "    finally:\n",
    "        del card_lib"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "ea2c97f1",
   "metadata": {},
   "source": [
    "# 修改TCON REG\n",
    "ANX TCON REG按照OSB ID——OFFSET——VALUE结构组织REG，\n",
    "如，osb = 0x00, offset 0x506 vale = 0x01，启动bist\n",
    "\n",
    "该启动BIST程序，仅用于智通VRRF测试版本code"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "id": "7aefce37",
   "metadata": {},
   "outputs": [],
   "source": [
    "try:\n",
    "    # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "    dll_path = \"./OperateCardLib.dll\"\n",
    "    card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "    card_lib.init(6)\n",
    "\n",
    "\n",
    "    card_lib.write_tcon_reg(0x00, 0x506, 0x01)\n",
    "\n",
    "\n",
    "    # Clean up\n",
    "    card_lib.free_lib()\n",
    "finally:\n",
    "    del card_lib\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "be84edb5",
   "metadata": {},
   "source": [
    "# MUX TIMING"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 33,
   "id": "b59bacf7",
   "metadata": {},
   "outputs": [
    {
     "data": {
      "application/vnd.jupyter.widget-view+json": {
       "model_id": "787e97a447a1425681594ff8c70bd11a",
       "version_major": 2,
       "version_minor": 0
      },
      "text/plain": [
       "interactive(children=(IntSlider(value=212, description='mux1_s_l', max=255), IntSlider(value=0, description='m…"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "import OperateCardLib\n",
    "from ipywidgets import interact\n",
    "import ipywidgets as widgets\n",
    "from IPython.display import display\n",
    "from ipywidgets import interactive\n",
    "\n",
    "try:\n",
    "    # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "    dll_path = \"./OperateCardLib.dll\"\n",
    "    card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "    card_lib.init(6)\n",
    "\n",
    "    def test_mux(mux1_s_l, mux1_s_h, mux1_e_l, mux1_e_h, mux2_s_l, mux2_s_h, mux2_e_l, mux2_e_h):\n",
    "        card_lib.write_tcon_reg(0x03, 0xd8, mux1_s_l)\n",
    "        card_lib.write_tcon_reg(0x03, 0xd9, mux1_s_h)\n",
    "\n",
    "        card_lib.write_tcon_reg(0x03, 0xdd, mux1_e_l)\n",
    "        card_lib.write_tcon_reg(0x03, 0xde, mux1_e_h)\n",
    "\n",
    "        card_lib.write_tcon_reg(0x03, 0xe8, mux2_s_l)\n",
    "        card_lib.write_tcon_reg(0x03, 0xe9, mux2_s_h)\n",
    "\n",
    "        card_lib.write_tcon_reg(0x03, 0xed, mux2_e_l)\n",
    "        card_lib.write_tcon_reg(0x03, 0xee, mux2_e_h)\n",
    "\n",
    "        print(\"reg:\",\"0xd8\",\"0xd9\",\"0xdd\",\"0xde\",\"0xe8\",\"0xe9\",\"0xed\",\"0xee\")\n",
    "        print(\"val:\", \n",
    "              \"0x{:02x}\".format(mux1_s_l), \"0x{:02x}\".format(mux1_s_h), \"0x{:02x}\".format(mux1_e_l), \"0x{:02x}\".format(mux1_e_h),\n",
    "              \"0x{:02x}\".format(mux2_s_l), \"0x{:02x}\".format(mux2_s_h),\"0x{:02x}\".format(mux2_e_l) ,\"0x{:02x}\".format(mux2_e_h)\n",
    "              )\n",
    "\n",
    "    val_list = []\n",
    "    for i in [0xd8, 0xd9, 0xdd, 0xde, 0xe8, 0xe9, 0xed, 0xee]:\n",
    "        val_list.append(card_lib.read_tcon_reg(0x03, i, 1))\n",
    "\n",
    "    w = interactive(test_mux, \n",
    "             mux1_s_l=(0, 255, 1), mux1_s_h=(0,2,1),\n",
    "             mux1_e_l=(0, 255, 1), mux1_e_h=(0,2,1),\n",
    "             mux2_s_l=(0, 255, 1), mux2_s_h=(0,2,1),\n",
    "             mux2_e_l=(0, 255, 1), mux2_e_h=(0,2,1)\n",
    "             )\n",
    "    \n",
    "    for i in range(8):\n",
    "        w.children[i].value = val_list[i]\n",
    "\n",
    "    display(w)\n",
    "\n",
    "\n",
    "finally:\n",
    "    pass\n",
    "        "
   ]
  },
  {
   "cell_type": "markdown",
   "id": "63bda833",
   "metadata": {},
   "source": [
    "# 启动PSR"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "e4011ec8",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib\n",
    "import time \n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # 启动PSR\n",
    "        card_lib.write_tcon_reg(0x00, 0x4e0, 0x81)\n",
    "\n",
    "        # 关闭PSR\n",
    "        #time.sleep(1)\n",
    "        #card_lib.write_tcon_reg(0x00, 0x4e0, 0x00)\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "markdown",
   "id": "7d2ecd12",
   "metadata": {},
   "source": [
    "# 启动BIST"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "id": "786ff5c5",
   "metadata": {},
   "outputs": [],
   "source": [
    "import OperateCardLib\n",
    "import time \n",
    "\n",
    "# Example of how to use the class\n",
    "if __name__ == \"__main__\":\n",
    "    try:\n",
    "        # Assuming the DLL is named 'OperateCardLib.dll' and located in the same directory\n",
    "        dll_path = \"./OperateCardLib.dll\"\n",
    "        card_lib = OperateCardLib.ANX_ANX2176(dll_path)\n",
    "\n",
    "        # Initialize the card\n",
    "        # CardID是以下值;intel_edp:0   intel_dp:1   amd_edp:2   nvidia:3  Qualcomm:5  amd_dp:6\n",
    "        card_lib.init(6)\n",
    "\n",
    "        # 启动PSR\n",
    "        card_lib.write_tcon_reg(0x00, 0x506, 0x01)\n",
    "\n",
    "        # 关闭PSR\n",
    "        #time.sleep(1)\n",
    "        #card_lib.write_tcon_reg(0x00, 0x4e0, 0x00)\n",
    "        # Clean up\n",
    "        card_lib.free_lib()\n",
    "    finally:\n",
    "        del card_lib\n",
    "        \n"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "id": "9d6e0ca9",
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.9.13"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
